using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Entities.Users;
using DotNetNuke.Security.Roles;
using DotNetNuke.Entities.Modules.Communications;

using System.Collections.Generic;

namespace Jfc007.WebLib
{
    public partial class Categories : PortalModuleBase, IModuleCommunicator
    {
        public event ModuleCommunicationEventHandler ModuleCommunication;
        protected void Page_Load(object sender, EventArgs e)
        {

           // ModuleCommunication = new ModuleCommunicationEventHandler( OnModuleCommunication );
       //     this.ModuleCommunication += new ModuleCommunicationEventHandler( OnModuleCommunication );
            
                DocumentsController objDocuments = new DocumentsController();
              // int modId = objDocuments.GetWebLibModuleId( PortalId );
                List<CategoryInfo> categories = objDocuments.GetCategories( PortalId, UserInfo.UserID );
                
                if (categories.Count > 0)
                {
                    gvCategories.DataSource = categories;
                    gvCategories.DataBind();
                }
                Session.Add( "Categories", categories );
              
           
        }

         public void OnModuleCommunication ( object sender, ModuleCommunicationEventArgs e  )
         {
             ModuleCommunication( this, e );
         }

       

       



        protected void gvCategories_SelectedIndexChanging ( object sender, GridViewSelectEventArgs e )
        {
            
            List<CategoryInfo> categories = (List<CategoryInfo>)Session["Categories"];
            
            ModuleCommunicationEventArgs oArgs = new ModuleCommunicationEventArgs();
            oArgs.Text = categories[e.NewSelectedIndex].Category;
            oArgs.Sender = "Categories";
            oArgs.Target = "MainPanel";

            if (ModuleCommunication != null)
                ModuleCommunication( this, oArgs );


        }



       



    }
}